using Microsoft.Xrm.Client;
using System.Collections.Generic;

namespace Sustainalytics.DynamicsCRMGateway.Tests
{
    public static class DictionaryExtensions
    {
        public static void AddEntityIfNotExists<T>(this Dictionary<int, T> dictionary, int index)
            where T : CrmEntity, INameable, new()
        {
            if (!dictionary.ContainsKey(index))
            {
                dictionary.AddEntity<T>(index);
            }
        }

        public static void AddEntity<T>(this Dictionary<int, T> dictionary, int index)
            where T : CrmEntity, INameable, new()
        {
            dictionary.Add(index, CrmTestDataHelper.CreateEntity<T>(index));
        }

        public static void AddToSet(this Dictionary<int, HashSet<int>> dictionary, int key, int value)
        {
            if (!dictionary.ContainsKey(key))
            {
                dictionary.Add(key, new HashSet<int>());
            }
            dictionary[key].Add(value);
        }
    }
}
